

#ifndef _READER_READER_H_
#define _READER_READER_H_

#include <stdint.h>
/* Status code definitions */
#include <ph_Status.h>
#include "phNfcLib.h"
#include "Debug.h"
#include "tag_type.h"
#include "SimpleTag.h"

#include "config/zkcfg.h"
//	#include "desfire/mifare.h"

#define RD_CFG_HFFirst		0x01U
#define RD_CFG_MFCheck		0x02U

#define RD_ATTR_HF		(1u << 0)
#define RD_ATTR_SE		(1u << 1)
#define RD_ATTR_LF		(1u << 2)
#define RD_ATTR_BT		(1u << 3)
#define RD_ATTR_HIDICLASS	(1u << 4)
#define RD_ATTR_HIDPROX		(1u << 5)

#define RD_ST_IDLE		0
#define RD_ST_CONFIG	1

typedef struct {
	SimpleTag_T tag;
	uint8_t credential[32];
	uint8_t clen;
	uint8_t nbit;
}credential_t;

//ECP(Enhanced Contactless Polling)
typedef struct {
	uint32_t tb_tci;
	uint8_t exr_tra;
}AppleWalletECParam_T;

typedef struct {
	void* handlerTimer;
	int life;
	int serviceCount;
	uint16_t handlerCard;
	uint8_t checkCount;
	uint8_t flag;
	uint8_t state;
	uint8_t length;
	uint8_t data[16];
}ReaderBLE_T;

typedef struct {
	int lastError;		//错误
	uint32_t hfFlags;	//支持的卡类型
	uint32_t lfFlags;	//支持的卡类型
	uint32_t config;	//配置开关：bit2--低频卡优先；bit3--验证MF卡UID。
	uint32_t attr;		//当前设备的属性：有无高频，有无SE芯片
	SimpleTag_T tag;
	int tagCount;
	SimpleTag_T curHfTag;
	AppleWalletECParam_T ecp;
	int hidState;
	void *pHal;
	void *pDiscLoop;
	uint32_t state;
	uint32_t bleFlags;
	int bleState;
	uint16_t bleAttr;
	ReaderBLE_T ble;
	uint16_t wPasPollConfig;
	uint16_t wActPollConfig;
	uint16_t wPasLisConfig;
	uint16_t wActLisConfig;
	uint16_t wSavePollTechCfg;
	uint16_t wTagsDetected;
	phNfcLib_ActivatedType_t dwActivatedType;
	// zkcfg_cfg_t zkcfg;
	// zkcfg_keys_t keys;
}Reader_T;

extern Reader_T reader;

uint32_t Reader_NFC_Init(void);

int Reader_NFC_Setup(void);

uint32_t Reader_NFC_LoadProfile(uint16_t wPasPollConfig, uint16_t wActPollConfig, 
		uint16_t wPasLisConfig, uint16_t wActLisConfig);

//	uint32_t Reader_NFC_Discovery(SimpleTag_T* info);

//	uint32_t Reader_NFC_Discovery2(SimpleTag_T* info, uint8_t seq);
uint32_t Reader_NFC_Discovery3(credential_t* cred, uint8_t seq);


uint32_t Reader_NFC_DiscoveryStd3(SimpleTag_T* info, uint16_t wPasPollConfig, uint8_t detect_count);

void Reader_NFC_SetPollSeq(uint8_t index);

uint32_t Reader_NFC_RfOff(void);

int reader_se_support(void);

#endif



